package com.example.houduan.Controller;

import com.example.houduan.Pojo.Doctor;
import com.example.houduan.Service.DoctorService;
import com.example.houduan.Utils.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Controller
@CrossOrigin
public class DoctorController {
    @Autowired
    DoctorService doctorService;

    @RequestMapping("/getAllDoctor")
    @ResponseBody
    public List<Doctor> getAllDoctor(){
        return doctorService.getAllDoctor();
    }

    @RequestMapping("/getDoctorPage")
    @ResponseBody
    public PageModel getDoctorPage(@RequestParam int num,int size){
        PageModel pm=doctorService.getDoctorPage(num,size);
        return pm;
    }

    @RequestMapping("/getDoctorByConditions")
    @ResponseBody
    public List<Doctor> getDoctorByConditons(@RequestParam String name,Integer sex,Integer level_id,String hospital){
        return doctorService.getDoctorByConditions(name,sex,level_id,hospital);
    }

    @RequestMapping("/addDoctor")
    @ResponseBody
    public String addDoctor(@RequestBody Doctor doctor){
        doctor.setCreatetime(LocalDateTime.now());
        doctor.setUpdatetime(LocalDateTime.now());
        if(doctorService.addDoctor(doctor)!=0){
            return "添加成功";
        }else {
            return "添加失败";
        }

    }

    @RequestMapping("/updateDoctor")
    @ResponseBody
    public String updateDoctor(@RequestBody Doctor doctor){
        doctor.setUpdatetime(LocalDateTime.now());
        System.out.println(doctor);
        if(doctorService.updateDoctor(doctor)!=0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }

    @RequestMapping("/deleteDoctor")
    @ResponseBody
    public String deleteDoctor(int id){
        if(doctorService.deleteDoctor(id)!=0){
            return "删除成功";
        }else {
            return "删除失败";
        }
    }


}
